// defination  of cube class



#include "Cube.h"

Cube::Cube(const char *fileName,const MyDisplay &another):Line(another){

  cube = new Matrix(fileName);
  
   if(cube->numRows() != 8 && cube->numCols() != 3)
      (*cube) = (*cube) * 0;
   
}

Cube::Cube(const Matrix &T){
  
   cube = new Matrix(T);
    if(cube->numRows() != 8 && cube->numCols() != 3)
      (*cube) = (*cube) * 0;
     
   
}

Cube::Cube(){

  cube = new Matrix(3,3);
}


Cube ::Cube(const Cube &another){

   (*this) = another;
}


Cube::~Cube(){

}



bool Cube::draw(dropAxis axis){


   double x1,y1,x2,y2;
   
   
   if(axis == z_axis){
   
   x1 = (double)(*cube)[0][0];
   y1 = (double)(*cube)[0][1];
   x2 = (double)(*cube)[1][0];
   y2 = (double)(*cube)[1][1];
   
   
   //           x1        y1          x2       y2    
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[0][0];
   y1 = (double)(*cube)[0][1];
   x2 = (double)(*cube)[2][0];
   y2 = (double)(*cube)[2][1];
    
  //           x1        y1          x3       y3      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[1][0];
   y1 = (double)(*cube)[1][1];
   x2 = (double)(*cube)[3][0];
   y2 = (double)(*cube)[3][1];
   
  //           x2        y2          x4       y4      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[2][0];
   y1 = (double)(*cube)[2][1];
   x2 = (double)(*cube)[3][0];
   y2 = (double)(*cube)[3][1];
   
  //           x3        y3          x4       y4      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[4][0];
   y1 = (double)(*cube)[4][1];
   x2 = (double)(*cube)[5][0];
   y2 = (double)(*cube)[5][1];
   
   
//XFillRectangle(show.display,show.win,show.gc,800,0,200,40);   
   
  //           x5        y5          x6       y6                
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[4][0];
   y1 = (double)(*cube)[4][1];
   x2 = (double)(*cube)[6][0];
   y2 = (double)(*cube)[6][1];
   
  //           x5        y5          x7       y7      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[5][0];
   y1 = (double)(*cube)[5][1];
   x2 = (double)(*cube)[7][0];
   y2 = (double)(*cube)[7][1];
   
  //           x6        y6          x8       y8      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[6][0];
   y1 = (double)(*cube)[6][1];
   x2 = (double)(*cube)[7][0];
   y2 = (double)(*cube)[7][1];
   
  //           x7        y7          x8       y8      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[0][0];
   y1 = (double)(*cube)[0][1];
   x2 = (double)(*cube)[4][0];
   y2 = (double)(*cube)[4][1];
   
    
   // connect these to rectangles  
   //           x1        y1          x5       y5      
 //  cout<<"Connecting those two rectangles"<<endl;
   
   
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[1][0];
   y1 = (double)(*cube)[1][1];
   x2 = (double)(*cube)[5][0];
   y2 = (double)(*cube)[5][1];
   
  //           x2        y2          x6       y6        
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[2][0];
   y1 = (double)(*cube)[2][1];
   x2 = (double)(*cube)[6][0];
   y2 = (double)(*cube)[6][1];
   
  //           x3        y3          x7       y7      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[3][0];
   y1 = (double)(*cube)[3][1];
   x2 = (double)(*cube)[7][0];
   y2 = (double)(*cube)[7][1];
   
  //           x4        y4          x8       y8      
    drawLine(x1,y1,x2,y2);
   
   
   
   
   }else 
     if(axis == y_axis){
   
   x1 = (double)(*cube)[0][0];
   y1 = (double)(*cube)[0][2];
   x2 = (double)(*cube)[1][0];
   y2 = (double)(*cube)[1][2];
   
   
   //           x1        y1          x2       y2    
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[0][0];
   y1 = (double)(*cube)[0][2];
   x2 = (double)(*cube)[2][0];
   y2 = (double)(*cube)[2][2];
    
  //           x1        y1          x3       y3      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[1][0];
   y1 = (double)(*cube)[1][2];
   x2 = (double)(*cube)[3][0];
   y2 = (double)(*cube)[3][2];
   
  //           x2        y2          x4       y4      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[2][0];
   y1 = (double)(*cube)[2][2];
   x2 = (double)(*cube)[3][0];
   y2 = (double)(*cube)[3][2];
   
  //           x3        y3          x4       y4      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[4][0];
   y1 = (double)(*cube)[4][2];
   x2 = (double)(*cube)[5][0];
   y2 = (double)(*cube)[5][2];
   
   
  //           x5        y5          x6       y6                
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[4][0];
   y1 = (double)(*cube)[4][2];
   x2 = (double)(*cube)[6][0];
   y2 = (double)(*cube)[6][2];
   
  //           x5        y5          x7       y7      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[5][0];
   y1 = (double)(*cube)[5][2];
   x2 = (double)(*cube)[7][0];
   y2 = (double)(*cube)[7][2];
    //           x6        y6          x8       y8      
    
    
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[6][0];
   y1 = (double)(*cube)[6][2];
   x2 = (double)(*cube)[7][0];
   y2 = (double)(*cube)[7][2];
     //           x7        y7          x8       y8      
     
   
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[0][0];
   y1 = (double)(*cube)[0][2];
   x2 = (double)(*cube)[4][0];
   y2 = (double)(*cube)[4][2];
   
  // cout<<"Connecting those two rectangles"<<endl;  
    
   // connect these to rectangles  
   //           x1        y1          x5       y5      
     
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[1][0];
   y1 = (double)(*cube)[1][2];
   x2 = (double)(*cube)[5][0];
   y2 = (double)(*cube)[5][2];
   
  //           x2        y2          x6       y6        
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[2][0];
   y1 = (double)(*cube)[2][2];
   x2 = (double)(*cube)[6][0];
   y2 = (double)(*cube)[6][2];
   
  //           x3        y3          x7       y7      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[3][0];
   y1 = (double)(*cube)[3][2];
   x2 = (double)(*cube)[7][0];
   y2 = (double)(*cube)[7][2];
   
  //           x4        y4          x8       y8      
    drawLine(x1,y1,x2,y2);
   
    
   } else
   if(axis == x_axis){
   
   
   
   
   x1 = (double)(*cube)[0][1];
   y1 = (double)(*cube)[0][2];
   x2 = (double)(*cube)[1][1];
   y2 = (double)(*cube)[1][2];
   
   
   //           x1        y1          x2       y2    
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[0][1];
   y1 = (double)(*cube)[0][2];
   x2 = (double)(*cube)[2][1];
   y2 = (double)(*cube)[2][2];
    
  //           x1        y1          x3       y3      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[1][1];
   y1 = (double)(*cube)[1][2];
   x2 = (double)(*cube)[3][1];
   y2 = (double)(*cube)[3][2];
   
  //           x2        y2          x4       y4      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[2][1];
   y1 = (double)(*cube)[2][2];
   x2 = (double)(*cube)[3][1];
   y2 = (double)(*cube)[3][2];
   
  //           x3        y3          x4       y4      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[4][1];
   y1 = (double)(*cube)[4][2];
   x2 = (double)(*cube)[5][1];
   y2 = (double)(*cube)[5][2];
   
   
  //           x5        y5          x6       y6                
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[4][1];
   y1 = (double)(*cube)[4][2];
   x2 = (double)(*cube)[6][1];
   y2 = (double)(*cube)[6][2];
   
  //           x5        y5          x7       y7      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[5][1];
   y1 = (double)(*cube)[5][2];
   x2 = (double)(*cube)[7][1];
   y2 = (double)(*cube)[7][2];
   
  //           x6        y6          x8       y8      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[6][1];
   y1 = (double)(*cube)[6][2];
   x2 = (double)(*cube)[7][1];
   y2 = (double)(*cube)[7][2];
   
  //           x7        y7          x8       y8      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[0][1];
   y1 = (double)(*cube)[0][2];
   x2 = (double)(*cube)[4][1];
   y2 = (double)(*cube)[4][2];
   
    
   // connect these to rectangles  
   //           x1        y1          x5       y5      
   //cout<<"Connecting those two rectangles"<<endl;
   
     
   
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[1][1];
   y1 = (double)(*cube)[1][2];
   x2 = (double)(*cube)[5][1];
   y2 = (double)(*cube)[5][2];
   
  //           x2        y2          x6       y6        
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[2][1];
   y1 = (double)(*cube)[2][2];
   x2 = (double)(*cube)[6][1];
   y2 = (double)(*cube)[6][2];
   
  //           x3        y3          x7       y7      
    drawLine(x1,y1,x2,y2);
    
   x1 = (double)(*cube)[3][1];
   y1 = (double)(*cube)[3][2];
   x2 = (double)(*cube)[7][1];
   y2 = (double)(*cube)[7][2];
   
  //           x4        y4          x8       y8      
    drawLine(x1,y1,x2,y2);
  }
   
   
    
    
    return true;

}


bool Cube::draw(const Matrix &T,char direction){


   if(T.numRows() !=  8 && T.numCols()  < 5){
        (*cube) = (*cube) * 0;
	//T.disp();
	//cout<<"Not a Cube"<<endl;
	return false;
   }
   
    
   (*cube) = T;
   
    (*cube) = cube->divRow(0,T[0][3]);	 
    (*cube) = cube->divRow(1,T[0][3]);
   (*cube) = cube->divRow(2,T[0][3]);
    (*cube) = cube->divRow(3,T[0][3]);
    (*cube) = cube->divRow(4,T[0][3]);
    (*cube) = cube->divRow(5,T[0][3]);
    (*cube)= cube->divRow(6,T[0][3]);
    (*cube) = cube->divRow(7,T[0][3]);
    
    
    

   if(cube->isColZero(0)){// cout<<"X-axis is 0"<<endl; draw(x_axis);  
    }  
   else 
   if(cube->isColZero(1)){ //cout<<"Y-axis is 0"<<endl;  draw(y_axis); 
   }
   else
   if(cube->isColZero(2)) {// cout<<"Z-axis is 0"<<endl; draw(z_axis); 
   }
   else
           { 
	    
	         if(direction = 'x') draw(x_axis);else
	         if(direction = 'y') draw(y_axis);else
	         if(direction = 'z') draw(z_axis);else draw(z_axis);
		  
	   }
   
   //T.disp();
      
/*   
     for (int i = 0 ; i< T.numRows(); ++i){
     
          for(int j=0 ; j<T.numCols();++j){
	  
	  
	  }
    }
  */ 
   return true;
}

